#include <iostream>
#include <string>

// 字符串的操作  拷贝 拼接 查找 替换   增 删 改 查

using namespace std;



int main(int argc, char const *argv[])
{
    // 字符串拼接

    string s1 = "hello ";
    string s2 = "小郑 ";

    string s3 = "莅临指导";

    string s4 = s1 + s2 + s3;
    s4.append("hello ");

    cout << "s1 = " << s1 << endl; 
    cout << "s2 = " << s2 << endl; 
    cout << "s3 = " << s3 << endl; 
    cout << "s4 = " << s4 << endl; 

    // strcmp
    s2 = s1;
    if (s1 == s2)
    {
        cout << "相等" << endl;
    }
    else
    {
        cout << "不相等" << endl;
    }
    // 查找 替换

    int pos = s1.find("l");
    cout << "pos" << pos << endl;

    if (pos == s1.npos)
    {
        cout << "没找到" << endl;
    }

    // replace  替换
    s1.replace(pos , 2 , "c++"); // he|c++|o    pos hello  ll l

    cout << s1 << endl;

    // 请求长度

    int len = s1.length();

    cout << len << endl;

    // 从字符串中读取
    char c_str[128] = "zhangsan";
    char ch =  c_str[1];

    cout << "ch = " << ch << endl;

    ch = s1[5];
    cout << "ch = " << ch << endl;

    // at
    ch = 'A';
    ch = s1.at(5);
    cout << "ch = " << ch << endl;


    // 插入 和 删除

    s1.insert(1 , "郑");

    cout << "s1 = " << s1 << endl;


    s1.erase(1 , 3);
    cout << "s1 = " << s1 << endl;

    // 清空
    s1.clear();

    cout << "s1 = " << s1 << endl;


    return 0;
}



